<?php
/* 
 *单证列表--待完成任务列表
 */
class ToDocumentAction extends CommonAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
            $where['logi_no'] = array('like',"%".$key."%");
            $where['Shipping.mano'] = array('like',"%".$key."%");
            $where['_logic'] = "or";
            $map['_complex'] = $where;
        }
        /*if( $_REQUEST['status'] != '' )
            $map['Shipping.status'] = $_REQUEST['status'];
        */
        if(!empty($_REQUEST['customer']))
            $map['Customer.name'] = array('like',"%".$_REQUEST['customer']."%");
        //time 
        $cond_time = array();
        if( $_REQUEST['start_time'] != '' )
          array_push($cond_time, array( 'egt' , strtotime($_REQUEST['start_time']) ) );
          //$cond_time = array( 'egt' , strtotime($_REQUEST['start_time']) );
        if( $_REQUEST['end_time'] != '' )
          array_push($cond_time, array( 'elt' , strtotime($_REQUEST['end_time']) ) );
	if(count($cond_time) >0 ){
  	    $map['create_time'] = $cond_time;	
	}
        $map['Shipping.status'] = array('eq',1); //单据待制作
    }

    public function index(){
        $map = $this->_search ();
        if (method_exists ( $this, '_filter' )) {
            $this->_filter ( $map );
        }
        
        $model = D ('ShippingOrderDetailView');
        if (! empty ( $model )) {
            $this->_list ( $model, $map,'',false,true );//group 去掉重复数据
        }
        $this->display ();
        return;
       //parent::index('ShippingOrderDetailView');
    }

    public function edit(){
        //TODO
        $model = M ( 'Shipping');
        $id = $_REQUEST [$model->getPk ()];
        $vo = $model->getById ( $id );
        $this->assign ( 'vo', $vo );
        $this->display ();
    }

    public function update()
    {
        A('Shipping')->update();
    }

     //相关产品
    public function detail($value='')
    {

        $map = 'shipping_id = '.intval($_REQUEST['id']) ;
        $count = M('Shipping_detail')->where($map)->count();
        if($count > 0){
            import ( "@.ORG.Page" );
            $page = new Page($count,25);
            $ps = M('Shipping_detail')->where($map)->limit($page->firstRow.','.$page->listRows)->order('id desc')->findAll(); 
            $assign_data = array(
                'products' => $ps,
                'page' => $page->show(),
            ); 
            $this->assign($assign_data);
        }
        $this->display();
    }
    

}
?>
